;solution for euler 65

(defun digital-sum (n)
	(let ((sum 0))
		(loop
			(when (= n 0) (return))
			(incf sum (mod n 10))
			(setf n (floor (/ n 10))))
		(return-from digital-sum sum)))

(defun e65 (level max)
	(let ((add 1) val)
		(when (= 1 (mod level 3))
			(setf add (* 2 (+ 1 (floor (/ level 3))))))
		(incf level)
		(when (= level max) (return-from e65 (/ 1 add)))

		(setf val (/ 1 (+ add (e65 level max))))
			;(format t "~a:~a  ~a~%" level add (+ 2 val))
		(return-from e65 val)))
		
(defun solve-euler65 ()
	(let ((num (numerator (+ 2 (e65 0 99)))))
		(format t "Euler 65:~a" (digital-sum num))))
